<?php
class Model_ServiceFactory {

	private static $dpt_id;

	static function Create($dpt_id)
	{
		if ($dpt_id==0){
			$model = new Model_ServiceCentral;
			return $model;
		}else{
		
			$db = Zend_Registry::get('db');
		
			$select = $db->select()
	             ->from(array('d' => 'acc_service_db'),array('dpt_id'))
	             ->join(array('s' => 'acc_service'), 's.dpt_id = d.dpt_id',array('service_name'))
	             ->where('d.dpt_id = ?', (int)$dpt_id)
	             ->group('d.dpt_id');
	
			$row = $db->fetchRow($select);
			//Zend_Debug::dump($row);
			
			if (!$row) 
			{
				// Error out because the user doesn't exist
				throw new Exception("service $dpt_id not found!");
			}
			else 
			{
				$class_name = 'Model_Service'.ucfirst(strtolower($row['service_name']));
				//Zend_Debug::dump($class_name);
				$path = APPLICATION_PATH.'/models';
				$file_name = $path."/".'Service'.ucfirst(strtolower($row['service_name'])).'.php';
				//Zend_Debug::dump($file_name);
				
				$model = "";
				if (is_file($file_name)) $model = new $class_name();
				//else throw new Exception('No service class' );  //for testing
				
				return $model;
			}
		}
	}
}